styleproperty: Use a custom resolve function for colors
authorBenjamin Otte <otte@redhat.com>
Tue, 3 Jan 2012 16:59:31 +0000 (17:59 +0100)
committerBenjamin Otte <otte@redhat.com>
Mon, 9 Jan 2012 17:37:57 +0000 (18:37 +0100)
We want to make sure to fall back to the initial value of the property
if resolving fails.

This is kinda tricky, because the initial value itself might need
resolving, too.

gtk/gtkcssstylepropertyimpl.c

index 053cafbc28c1150c390199159030c32dbe128364..62dffe35461e30670a1ee27006a068d61de07378 100644 (file)
@@ -53,6 +53,9 @@ color_compute (GtkCssStyleProperty    *property,
 {
   g_value_init (computed, GDK_TYPE_RGBA);
 
+  /* for when resolvage fails */
+restart:
+
   if (G_VALUE_HOLDS (specified, GTK_TYPE_CSS_SPECIAL_VALUE))
     {
       GtkStyleContext *parent = gtk_style_context_get_parent (context);
@@ -65,8 +68,22 @@ color_compute (GtkCssStyleProperty    *property,
                                       context,
                                       _gtk_css_style_property_get_initial_value (property));
     }
+  else if (G_VALUE_HOLDS (specified, GTK_TYPE_SYMBOLIC_COLOR))
+    {
+      GdkRGBA rgba;
+
+      if (!_gtk_style_context_resolve_color (context,
+                                             g_value_get_boxed (specified),
+                                             &rgba))
+        {
+          specified = _gtk_css_style_property_get_initial_value (property);
+          goto restart;
+        }
+
+      g_value_set_boxed (computed, &rgba);
+    }
   else
-    _gtk_css_style_compute_value (computed, context, specified);
+    g_value_copy (specified, computed);
 }
 
 static void
@@ -462,7 +479,7 @@ _gtk_css_style_property_init_properties (void)
                                           0,
                                           NULL,
                                           NULL,
-                                          NULL,
+                                          color_compute,
                                           &rgba);
 
   gtk_style_property_register            ("font-family",
@@ -663,28 +680,28 @@ _gtk_css_style_property_init_properties (void)
                                           0,
                                           NULL,
                                           NULL,
-                                          NULL,
+                                          color_compute,
                                           &value);
   _gtk_style_property_register           ("border-right-color",
                                           GDK_TYPE_RGBA,
                                           0,
                                           NULL,
                                           NULL,
-                                          NULL,
+                                          color_compute,
                                           &value);
   _gtk_style_property_register           ("border-bottom-color",
                                           GDK_TYPE_RGBA,
                                           0,
                                           NULL,
                                           NULL,
-                                          NULL,
+                                          color_compute,
                                           &value);
   _gtk_style_property_register           ("border-left-color",
                                           GDK_TYPE_RGBA,
                                           0,
                                           NULL,
                                           NULL,
-                                          NULL,
+                                          color_compute,
                                           &value);
   g_value_unset (&value);